import math
import os

def mmNorm(f):
    file = open(f,'r')
    lines = []
    for l in file.readlines():
        lines.append(l.split())
    file.close()
    #assume fist is label second is class scale between [-1;1]
    mi = []
    ma = []
    
    #for all columns find min and max
    for i in xrange(2,len(lines[0])):  
       temp = []
       for ll in lines:
           temp.append(float(ll[i]))
       ma.append(max(temp))
       mi.append(min(temp))        
    
    #normlize the mofus
    for l in lines:
        for i in xrange(2,len(lines[0])):
            l[i] = str(2*(float(l[i])- mi[i-2])/(ma[i-2]-mi[i-2])-1)
    
    path = os.path.dirname(f)
    ff = os.path.dirname(f) + '/MMnorm' + os.path.basename(f)
    print "--> Writting Min Max normalization of dataset"
    print "    " + ff
    file = open(ff,'w')
    for ll in lines:
        file.writelines("\t".join(ll)+'\n')
    file.close()
    